﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using SaiLing.Domain;
using SaiLing.Repository;
using SaiLing.SingleSignOn.Application.Service.Interfaces.System;
using SaiLing.SingleSignOn.Domain.Entities.DataTransferObject;
using SaiLing.SingleSignOn.Domain.Entities.System;
using SaiLing.SingleSignOn.Domain.Interfaces.System;
using SaiLing.Web;

namespace SaiLing.SingleSignOn.Application.Service.Providers.System
{
    public class OperationLogService : BaseService<OperationLog>, IOperationLogService
    {
        public OperationLogService(IUnitOfWork unitOfWork, IOperationLogRepository repository) : base(unitOfWork, repository)
        {
        }

        public Task LogAsync(string type, string content, LogUser user, string remark = null)
        {
            var entity = new OperationLog
            {
                Ip = HttpContext.GetIpAddress(),
                OperatorType = type,
                LogType = user.LogType,
                OperatorContent = content,
                OperatorRemark = remark,
                UserName = user.LoginName,
                UserId = user.Id
            };
            Add(entity);
            return UnitOfWork.SaveChangesAsync();
        }
    }
}
